<?php
/**
 * @author Vu    <>
 * Description : cấu hình danh mục
 */
class DanhmucController extends Zend_Controller_Action
{
	/*
	 * admin888 <doan.hut@gmail.com>
	 * Description : dùng chung cho action
	 */		
    public function init()
    {
        
      $auth = Zend_Auth::getInstance();
	  if($auth->hasIdentity()){
			$data = $auth->getIdentity();
			$this->view->name = $data->name;
			$this->view->iddangnhap = $data->uid;
			$this->_uid = $data->uid;
	  		if ( $data->leve != 1 ){
				$this->_redirect('index');
			}
			$cd = new Model_Caidat();
			$thongbao = $cd->getthongbao($data->uid);
			$this->view->thongbao = $thongbao;			
			
	   }
       //phần lay out trên
	   $this->view->today =$date =new Zend_Date();
       $reponse = $this->getResponse();
       $reponse->insert('top', $this->view->render('index/top.phtml'));
       $this->view->title = " Cài đặt danh mục thư- Email Manager ";
       
    }
	/**
     * admin888 <doan.hut@gmail.com>
     * Description : check nếu chưa login thì chuyển về trang ngoài
     * Note hàm này mọi người có thể dung chung
     */
	public function preDispatch()
	{
	    $auth = Zend_Auth::getInstance();
	    if (!$auth->hasIdentity()) {
	        if ($this->_request->getActionName() != 'login') {
	            $this->_redirect('login');
	        }
	    }
	}
    /**
     * admin888 <paven@gmail.com>
     * Enter description :check user login 
     * leve = 1 thi admin se config cho toan bo thanh vien duoc
     * leve = 3 thi chi sua duoc cua user thoi 
     */
    public function indexAction()
    {
   	   $auth = Zend_Auth::getInstance();
	   if($auth->hasIdentity()){
			$data = $auth->getIdentity();
			$leve = $data->leve;
			if ($leve == 1){
				$this->_redirect('danhmuc/listdanhmtm');
			}elseif ($leve == 3){
				$this->_redirect('index');
			}
		
	   }else{
	   		$this->_redirect('index');
	   } 	
    }
    /**
     * @author : Quyenvv
     * Enter description here ...
     */
    public function listdanhmtmAction()
    {
		$cl   = new Model_Danhmuc();
		$data = $cl->getallchung();
		$this->view->danhmuc = $data;
    }
    /**
     * @author : Quyenvv
     * Enter description: xóa 1 danh mục
     */
    public function xoadanhmucAction()
    {
    	$dm = new Model_Danhmuc();
    	$iddm = $this->_getParam('idtm');
    	$xoa = $dm->xoadanhmuc($iddm);
    	$this->getHelper('viewRenderer')->setNoRender(); // set khong su dung template
        $this->_helper->layout->disableLayout(); //disable layout
    }
    
	public function battatdanhmucAction()
	{
		$dm = new Model_Danhmuc();
		$data = $this->_getAllParams('');
		$ud = $dm->getupdatedanhmuc($data);
		
	}
	
	public function battatlienheAction()
	{
		$lh = new Model_Lienhe();
		$data = $this->_getAllParams();
		$ud = $lh->getupdatelienhe($data);
		
	}

	
	/**
	 * Quyenvv
	 * Thêm mới thông tin danh mục
	 */
	public function themdanhmucAction()
	{
		$dm =new Model_Danhmuc();
		$data = $this->_getAllParams();
		//echo $data['tendanhmuc'];die();
		$add = $dm->adddanhmuc($data,$this->_uid);
		if($add){
			$this->_redirect('danhmuc/listdanhmtm');
		}

	}
	
	public function suadanhmucAction()
	{
		$dm = new Model_Danhmuc();
		$data = $this->_getAllParams();
		$update = $dm->updatedanhmuc($data);
		$this->_redirect('danhmuc/listdanhmtm');
	}
	
	
}